JavaScript

DatetoCalendar Method

Syntax

Date.toCalendar([type[,showTime]])

Arguments

typestring

The type of date to show. Value can be "abbreviated", "standard" or "extended".

showTimestring

When to show the time component of the date. Value can be "always", "never", "day" (the default), "3-day", "today", "month" or "year".

Description

Extension to the native date variable to allow the conversion of the date into a calendar date relative to the current date.

Discussion

The Date.toCalendar method converts the date into a friendly string format just as "next Monday at 2:00pm" or "Friday 21st May". The templates and formats used to generate the string are stored in A5.d.date.calendar.

There are three types of calendar dates "abbreviated", "standard" and "extended". An "abbreviated" date is meant to be used to show the date in the shortest friendly format, such as "1st June". A "standard" date is meant to be used to show the date in a slightly more verbose format "Mon 1st June". While the "extended" date is meant to be used to show the date in a long format, such as "Monday the 1st of June".

The "showTime" argument controls when the time is displayed. By default it is set to "day", meaning that any calendar date that is within the range of relative days will show the time, such as "next Wednesday at 2:00pm" but not "1st Jun". A "showTime" of month will show the time for all dates within the month, a value of "year" will show the time for all dates within the year, and a value of "always" will always so the time.

Example

var d = new Date();
d.adjust('day',2);
d.setClock('2pm');
var dStr = d.toCalendar();
// dStr = 'next Wednesday at 2:00pm'